import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { BaseHttpService } from '../../../shared/services/baseHttp.service';
import { Observable } from 'rxjs/Observable';
import { StorageService } from '../../../shared/services/storage.service';
import { ChartPointModel } from '../../../shared/models/chartPoint.model';
import { ClusterModelWrapper } from '../riskCluster/cluster.model';
import { CompanyCountModel } from '../../../shared/models/companyCount.model';
import { ProductInvolvementFilterModel } from './models/productInvolvementFilter.model';

/**
 * Overall Product Involvement main service
 * 
 * Author: Andrei Istrate
 * Date: 11.05.2018
 */
@Injectable()
export class ResearchProductInvolvementService extends BaseHttpService {
    constructor(private http: HttpClient) {
        super();
    }

    /**
     * Get list of companies with Product Involvement
     * @param filters Product Involvement list filter object
     * @param skip Index to take from
     * @param take Number of companies to take
     * @param orderBy Name of column to order by
     * @param orderByAsc True to order ascending by the 'orderBy' column or false for descending
     */
    
    public getCompanies(filters: ProductInvolvementFilterModel, skip: number, take: number, orderBy: string, orderByAsc: boolean, accountId:string): any {
        let params: HttpParams = new HttpParams();
        params = params.set("skip", skip.toString())
            .set("take", take.toString())
            .set('getCount', 'false')
            .set('orderBy', orderBy)
            .set('includeAllFields', 'true')
            .set('orderAscending', orderByAsc.toString())
            .set('accountId', accountId);
        params = this.urlEncodeObject(filters, params, 'CompanyNameLowerCase');
        //because of the HppClient issue with '+' and probably other special chars, we set the parameter into the url
        return this.http.get<any[]>(this.serverUrl + 'productinvolvementserv/api/v1/companyassessments?CompanyNameLowerCase=' + this.paramEncode(filters, 'CompanyNameLowerCase'), { params: params });
    }
    
    /** 
     * Get number of companies after the input filter is applied
     * @param filters Product Involvement list filter object
     */
    
     public getCompaniesCount(filters: ProductInvolvementFilterModel, accountId:string): any {
        let params: HttpParams = new HttpParams();
        params = params.set("getCount", 'true')
        .set('accountId', accountId);
        params = this.urlEncodeObject(filters, params, 'CompanyNameLowerCase');
        //because of the HppClient issue with '+' and probably other special chars, we set the parameter into the url
        return this.http.get<any>(this.serverUrl + 'productinvolvementserv/api/v1/companyassessments?CompanyNameLowerCase=' + this.paramEncode(filters, 'CompanyNameLowerCase'), { params: params });
    } 

    public getIndicatorsList(): any {
        let params: HttpParams = new HttpParams();
        params = params.set("getIndicators", 'true');
        return this.http.get<any[]>(this.serverUrl + 'productinvolvementserv/api/v1/companyassessments', { params: params });
    }

    public getIndustriesList(): any {
        let params: HttpParams = new HttpParams();
        params = params.set("getIndustries", 'true');
        return this.http.get<any[]>(this.serverUrl + 'productinvolvementserv/api/v1/companyassessments', { params: params });
    }

}